package com.leyou.common.advice;

import com.leyou.common.exceptions.LyException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class CommonExceptionAdvice {

    /**
     * 统一异常处理器
     * 通过@ExceptionHandler(RuntimeException.class)指定要拦截的异常的类型
     */
    @ExceptionHandler(LyException.class)
    public ResponseEntity<String> handleException(LyException e){
        // 返回自定义信息
        return ResponseEntity.status(e.getStatus()).body(e.getMessage());
    }
}
